<?php
/*
 * Author:  Somnath Shinde- soma.shinde@gmail.com Mobile No:- 9423792564
 * 
 * Create Date: 
 * 
 * Version of MYSQL_to_PHP: 1.1
 * 
 * Ranzani( YZ'S );
 * 
 */
//require_once 'classes/DataBaseMysql.class.php';

Class BaseAppointments {

	protected $m_intId;
	protected $m_intPatientId;
	protected $m_intDoctorId;
	protected $m_strDateTime;
	protected $m_intRoomNumber;
	protected $m_strNote;
	protected $m_intIsRemainder;
	protected $m_strOverView;
	protected $connection;

	public function  __construct() {
		if( true == isset( $_SERVER['connection'] ) ) {
			$this->connection = $_SERVER['connection'];
		}
	}

	
	/*******************************************************************************************
	******************************** get Functions *********************************************
	*******************************************************************************************/

	public function getId(){
		return $this->m_intId;
	}

	public function getPatientId(){
		return $this->m_intPatientId;
	}

	public function getDoctorId(){
		return $this->m_intDoctorId;
	}

	public function getDateTime(){
		return $this->m_strDateTime;
	}

	public function getRoomNumber(){
		return $this->m_intRoomNumber;
	}

	public function getNote(){
		return $this->m_strNote;
	}

	public function getIsRemainder(){
		return $this->m_intIsRemainder;
	}

	public function getOverView(){
		return $this->m_strOverView;
	}
	
	/*******************************************************************************************
	********************************* set Functions ********************************************
	*******************************************************************************************/

	public function setId( $Id ){
		$this->m_intId = $Id;
	}

	public function setPatientId( $PatientId ){
		$this->m_intPatientId = $PatientId;
	}

	public function setDoctorId( $DoctorId ){
		$this->m_intDoctorId = $DoctorId;
	}

	public function setDateTime( $DateTime ){
		$this->m_strDateTime = $DateTime;
	}

	public function setRoomNumber( $RoomNumber ){
		$this->m_intRoomNumber = $RoomNumber;
	}

	public function setNote( $Note ){
		$this->m_strNote = $Note;
	}

	public function setIsRemainder( $IsRemainder ){
		$this->m_intIsRemainder = $IsRemainder;
	}

	public function setOverView( $OverView ){
		$this->m_strOverView = $OverView;
	}
	
	/*******************************************************************************************
	********************************* Insert Functions ********************************************
	*******************************************************************************************/

	public function insert(){
		return $this->connection->RunQuery( "Insert into APPOINTMENTS (patient_id, doctor_id, date_time, room_number, note, is_remainder, over_view) values (" . $this->getPatientId() . ", " . $this->getDoctorId() . ", '" . $this->getDateTime() . "', " . $this->getRoomNumber() . ", '" . $this->getNote() . "', " . $this->getIsRemainder() . ", '" . $this->getOverView() . "')");
	}
	
	/*******************************************************************************************
	********************************* Update Functions ********************************************
	*******************************************************************************************/

	public function update(){
		return $this->connection->RunQuery( "UPDATE APPOINTMENTS set  patient_id= " . $this->getPatientId() . ", doctor_id= " . $this->getDoctorId() . ", date_time= '" . $this->getDateTime() . "', room_number= " . $this->getRoomNumber() . ", note= '" . $this->getNote() . "', is_remainder= " . $this->getIsRemainder() . ", over_view= '" . $this->getOverView() . "' where id =" . $this->getId() );
	}
	
	/*******************************************************************************************
	********************************* Delete Functions ********************************************
	*******************************************************************************************/

	public function Delete($intId ) {
		$this->connection->RunQuery( "DELETE FROM appointments WHERE id = $intId");
	}

	public function fetchNextId() {
		$result = $this->connection->RunQuery( "SELECT AUTO_INCREMENT as id FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '" . DB_DATABASE . "' AND TABLE_NAME = 'appointments'" );
		if( false == $result ) return NULL;

		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$this->id = $row["id"];
		}

		return $this->id;
	}

}